package org.dawfinn.droiditarian.data;

import java.util.Date;

public class Deed {

	private static final long serialVersionUID = 1L;

	private Integer id;
	private final String name;
	private final String description;
	private final String explanation;
	private final String moreInfo;
	private final String serverId;
	private boolean favorite;
	private boolean completed;
	private final Date releaseDate;
	private OnDeedChangeListener changeListener;

	public Deed(int id, String name, String description, String reason,
			String moreInfo, String serverId, boolean favorite, boolean completed,
			Date releaseDate) {
		this(name, description, reason, moreInfo, serverId, releaseDate);
		this.id = id;
		this.favorite = favorite;
		this.completed = completed;
	}

	public Deed(String name, String description, String reason, String moreInfo,
			String serverId, Date releaseDate) {
		this.id = null;
		this.name = name;
		this.description = description;
		this.explanation = reason;
		this.moreInfo = moreInfo;
		this.serverId = serverId;
		favorite = false;
		completed = false;
		this.releaseDate = releaseDate;
	}

	public boolean hasId() {
		return id != null;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public String getDescription() {
		return description;
	}

	public String getExplanation() {
		return explanation;
	}

	public String getMoreInfo() {
		return moreInfo;
	}

	public String getServerId() {
		return serverId;
	}

	public boolean isFavorite() {
		return favorite;
	}

	public void setFavorite(boolean favorite) {
		this.favorite = favorite;
	}

	public boolean isCompleted() {
		return completed;
	}

	public void setCompleted(boolean completed) {
		this.completed = completed;
	}

	public Date getReleaseDate() {
		return releaseDate;
	}

	public void setOnDeedChangeListener(OnDeedChangeListener listener) {
		this.changeListener = listener;
	}

	/**
	 * Notify the deed change listener that this deed has been changed.
	 */
	public void notifyOnDeedChangeListener() {
		if (changeListener != null) {
			changeListener.onDeedChanged(this);
		}
	}

	/**
	 * Interface for a callback to be invoked when the deed is changed.
	 */
	public interface OnDeedChangeListener {
		/**
		 * Called when the deed changes state
		 * 
		 * @param deed
		 *           the deed that was changed
		 */
		public void onDeedChanged(Deed deed);
	}
}
